import isLogin from "/client/utils/isLogin.js"
const user = document.querySelector(".user")
const logined = document.querySelector(".login")
// 注销登录按钮
const delLogin = document.querySelector(".delLogin")

delLogin.onclick = del

login()
// 验证登录
async function login() {
  const res = await isLogin()
  if (!res.state) {
    // 未登录
    user.style.display = "none"
    logined.style.display = "block"
  } else {
    // 已登录
    user.style.display = "block"
    logined.style.display = "none"
    user.children[0].innerHTML = res.data.username
  }
}

// 注销登陆
async function del(){
  // 删除本地信息
  localStorage.removeItem("token")
  login()
}